/*
 * Saphre - Suffix Arrays for Phrase Extraction
 * Copyright (C) 2013 
 * Dale Gerdemann - Tübingen, Germany 
 * Niko Schenk - Frankfurt am Main, Germany
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package serialization;

import saphre.commands.CmdGappy;
import saphre.commands.CmdShowLcpInterSl;

/**
 * This class enumerates web access to the Saphre platform.
 *
 * @author Niko Schenk, Zeeshan Mustafa
 */
public class SaphreWebDemo {

    public static final String PATH_TO_CORPUS = "src/main/resources/corpusProjects/testcorpus/corpus";
    public static SaphreWebRouter swr = null;

    static SaphreSerializerMeta ssm = new SaphreSerializerMeta();

    public static void main(String[] args) throws Exception {
       
        // load the corpus.
        SaphreWebRouter swr = new SaphreWebRouter();
 
        ssm = swr.loadCorpusFromDisk(PATH_TO_CORPUS, ".\n"
                + ",\n"
                + "!\n"
                + "?\n"
                + "*\n"
                + "(\n"
                + ")\n"
                + "\"\n"
                + "'\n"
                + ";\n"
                + ":\n"
                + "[\n"
                + "]\n"
                + "â€”\n"
                + "-\n", "#\\n\\n+|\n"
                + "--|\n"
                + "Mr.|\n"
                + "\\w+in'|   # shortened -ing word\n"
                + "\\w+s'|    # apostrophe after plural\n"
                + "'em|\n"
                + "s'pose|\n"
                + "o'clock|\n"
                + "'balmed|\n"
                + "reg'lar|\n"
                + "sou'-wester|\n"
                + "\\w+([â€™']([dmst]|re|ve|ll))?|  # apostrophe: \n"
                + "\\w+(-\\w+)+|\n"
                + "\\p{P}        # punctuation\n", "not yet used");
        SaphreWebRouter.SaphreDeserializedObject sdo = swr.deserializeSaphreFromDisk(PATH_TO_CORPUS);
        System.out.println(sdo.sa.getIndices().length);

        // Run lcp inter sl command.
        CmdShowLcpInterSl lcpInterSl = new CmdShowLcpInterSl();
        lcpInterSl.Query(sdo.store, sdo.sa, sdo.top);


    }

    /**
     * 
     * @param pathToCorpus
     * @throws Exception 
     */
    public static void serializeCorpusAndLoadOptions(String pathToCorpus) throws Exception {

        // TOOD:
        // make this unstatic.


        // load the corpus.
        swr = new SaphreWebRouter();
        // writes serilized files to the corpus path directory into "loadOptions".
        ssm = swr.loadCorpusFromDisk(pathToCorpus, ".\n"
                + // boundary.
                ",\n"
                + "!\n"
                + "?\n"
                + "*\n"
                + "(\n"
                + ")\n"
                + "\"\n"
                + "'\n"
                + ";\n"
                + ":\n"
                + "[\n"
                + "]\n"
                + "â€”\n"
                + "-\n",
                // regex.
                "#\\n\\n+|\n"
                + "--|\n"
                + "Mr.|\n"
                + "\\w+in'|   # shortened -ing word\n"
                + "\\w+s'|    # apostrophe after plural\n"
                + "'em|\n"
                + "s'pose|\n"
                + "o'clock|\n"
                + "'balmed|\n"
                + "reg'lar|\n"
                + "sou'-wester|\n"
                + "\\w+([â€™']([dmst]|re|ve|ll))?|  # apostrophe: \n"
                + "\\w+(-\\w+)+|\n"
                + "\\p{P}        # punctuation\n",
                // normalizer.
                "not yet used");


    }

    /**
     * Deserialize data and run query on binary data.
     * @param pathToCorpus
     * @throws Exception 
     */
    public static void deserializeDataAndRunSampleQuery(String pathToCorpus) throws Exception {
        SaphreWebRouter.SaphreDeserializedObject sdo = swr.deserializeSaphreFromDisk(pathToCorpus);
        //System.out.println(sdo.sa.getIndices().length);
        // Run gappy phrases command.
        CmdGappy gappy = new CmdGappy();
        // Extract gappy phrases with default parameter values.
        gappy.executeCommandGappy(sdo.store, sdo.pa, sdo.top, sdo.sa);
    }
}
